package com.jieao.front.controller;

import com.jieao.common.core.controller.BaseController;
import com.jieao.common.core.domain.Ztree;
import com.jieao.common.core.page.TableDataInfo;
import com.jieao.content.dto.ArticleDto;
import com.jieao.content.dto.CatalogDto;
import com.jieao.content.dto.DiaryDto;
import com.jieao.content.service.ICatalogService;
import com.jieao.content.service.IDiaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Description 日记页面 控制器
 * @Author weifanl
 * @Date2020/7/12 13:14
 **/
@Controller
@RequestMapping("/front/diary")
public class FrontDiaryController extends BaseController {
    @Autowired
    private IDiaryService diaryService;
    @Autowired
    private ICatalogService catalogService;

    @GetMapping(value = "")
    public String diary() {
        return "front/diary";
    }

    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData(CatalogDto catalogDto) {
        List<Ztree> ztrees = catalogService.selectCatalogTree(catalogDto);
        return ztrees;
    }

    @GetMapping("/timeData")
    @ResponseBody
    public List<Map<String,Object>> timeData(CatalogDto catalogDto) {
        List<Map<String,Object>> data = diaryService.getTimeData(catalogDto.getId());
        return data;
    }

    /**
     * 分页获得日记
     * @param
     * @return {com.jieao.common.core.page.TableDataInfo}
     * @author LWF
     * @date 2020/7/12 13:16
     **/
    @PostMapping(value = "/diaryList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public TableDataInfo diaryList(DiaryDto diary) {
        startPage();
        List<DiaryDto> diaryDtos = diaryService.selectFrontDiaryList(diary);
        return getDataTable(diaryDtos);
    }

    /**
     * 日记详情页
     * @param diaryId
     * @param mmap
     * @return {java.lang.String}
     * @author LWF
     * @date 2020/7/12 23:20
     **/
    @GetMapping(value = "/diaryDetil")
    public String diaryDetil(Long diaryId, ModelMap mmap) {
        DiaryDto diaryDto = diaryService.selectDiaryById(diaryId);
        mmap.put("article", diaryDto);
        return "front/diaryDetil";
    }

}
